How to Create an LinkedList<String, int> Anonymous User242504-Oct-2013I want to create an LinkedList of couple that the key is a String and the value is an integer ?javajava Updated on 04-Oct-2013
Anonymous User
04-Oct-2013You can only use Object in a LinkedList., this means you cant use Java Primitives. However, what you seem to need is a Map structure.
I recommend using java.util.HashMap, it allows you to create a Key, Value pairs.
Example:
LinkedHashMap<String, Integer> b = newLinkedHashMap<String,Integer>();
b.put("one",1);
b.put("two",2);
b.put("a",3);
for (String key:b.keySet())
{
System.out.println(b.get(key)); // print 1 then 2 finally 3
}
Hope this is what you were asking (if so, modify your question).